package cn.hty.mymsg.api.service;


import cn.hty.mymsg.api.domain.RecallTaskModel;
import cn.hty.mymsg.common.enums.RespStatusEnum;
import cn.hty.mymsg.common.pipeline.ProcessContext;
import cn.hty.mymsg.common.pipeline.ProcessController;
import cn.hty.mymsg.common.vo.BasicResultVO;
import cn.hty.mymsg.service.domain.SendRequest;
import cn.hty.mymsg.service.domain.SendResponse;
import cn.hty.mymsg.service.service.RecallService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Service
public class RecallServiceImpl implements RecallService {
    @Autowired
    @Qualifier("apiProcessController")
    private ProcessController processController;

    @Override
    public SendResponse recall(SendRequest sendRequest) {

        if (ObjectUtils.isEmpty(sendRequest)) {
            return new SendResponse(RespStatusEnum.CLIENT_BAD_PARAMETERS.getCode(), RespStatusEnum.CLIENT_BAD_PARAMETERS.getMsg(), null);
        }
        RecallTaskModel recallTaskModel = RecallTaskModel.builder().messageTemplateId(sendRequest.getMessageTemplateId())
                .recallMessageId(sendRequest.getRecallMessageIds()).build();
        ProcessContext context = ProcessContext.builder().code(sendRequest.getCode()).processModel(recallTaskModel).needBreak(false).response(BasicResultVO.success()).build();
        ProcessContext process = processController.process(context);
        return new SendResponse(process.getResponse().getStatus(), process.getResponse().getMsg(), null);
    }
}
